#!/bin/sh
################################################################################
# extras
#
# This script (downloads and) mounts the extras directory tree.
################################################################################
. /etc/rc.d/functions

start() {
    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/extras] Starting..."

    if [ -n "${MM_EXTRAS_URL}" ] ; then

        if [ ! "x${MM_EXTRAS_URL}" = "xauto" ] && [ ! "x${MM_EXTRAS_URL}" = "xglobal" ] ; then
            /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/extras] Mounting Extras dir from ${MM_EXTRAS_URL}"
            mm_url_mount "${MM_EXTRAS_URL}" "/usr/local"
            /sbin/ldconfig
        fi

        if [ "x${MM_EXTRAS_URL}" = "xauto" ] ; then
            mm_message_output info "mounting extras ...(auto)"
            if [ -f "/var/lib/minimyth.bootdir.nfs_mounted" ] ; then
                /bin/rm -rf /usr/local
                /bin/ln -sf /var/minimyth.bootdir/extras/${HOST_NAME} "/usr/local"
                /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/media] Extras dir automounted...(auto)"
                /sbin/ldconfig
            else
                /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/media] ERROR: Extras not avaliale because NFS base dir not mounted...(auto)"
                exit 1
            fi
        fi

        if [ "x${MM_EXTRAS_URL}" = "xglobal" ] ; then
            mm_message_output info "mounting extras ...(global)"
            if [ -f "/var/lib/minimyth.bootdir.nfs_mounted" ] ; then
                /bin/rm -rf /usr/local
                /bin/ln -sf /var/minimyth.bootdir/extras "/usr/local"
                /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/media] extras dir automounted...(global)"
                /sbin/ldconfig
            else
                /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/media] ERROR: Extras not avaliale because NFS base dir not mounted...(global)"
                exit 1
            fi
        fi
    fi

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/extras] Started with return code=0..."

    return 0
}

stop() {

    /bin/umount "${MM_EXTRAS_URL}"
    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
